package com.haoshuang.zhouzhoubang.ui.adapter


import androidx.recyclerview.widget.GridLayoutManager
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.ItemSkillRightBinding
import com.haoshuang.zhouzhoubang.model.bean.SortBean
import com.haoshuang.zhouzhoubang.utils.DrawableUtils
import com.mufeng.libs.base.BaseBindingHolder
import com.mufeng.libs.base.BaseBindingQuickAdapter


/**
 * 订单模块中的订单列表适配器
 * */
class SkillRightAdapter(data: MutableList<SortBean.Data>) :
    BaseBindingQuickAdapter<SortBean.Data, ItemSkillRightBinding>(data){

    override fun onBindViewHolder(holder: BaseBindingHolder, position: Int, item: SortBean.Data?) {
        if (item==null) return

        val binding = ItemSkillRightBinding.bind(holder.itemView)
        var adapter=SkillAdapter(item.data_list)
        var isAll=1
        if (item.data_list.size>0){
            for (b in item.data_list){
                if (b.isCheck==0){
                    isAll=0
                    break
                }
            }
        }else{
            isAll=0
        }
        binding.apply {
            if (isAll==1){
                item.isCheck2=1
                DrawableUtils.setTextImage(context, R.mipmap.icon_yty,tvAll,0)
            }else{
                item.isCheck2=0
                DrawableUtils.setTextImage(context, R.mipmap.icon_wty,tvAll,0)
            }

            tvName.text=item.cate_name
            rvList.layoutManager=GridLayoutManager(context,2)
            rvList.adapter=adapter
            adapter.setOnItemClickListener { adapter, view, position ->

                if (item.data_list[position].isCheck==0){
                    item.data_list[position].isCheck=1
                    adapter.notifyItemChanged(position)
                    var isAll=1
                    for (b in item.data_list){
                        if (b.isCheck==0){
                            isAll=0
                            break
                        }
                    }
                    if (isAll==1){
                        item.isCheck2=1
                        DrawableUtils.setTextImage(context, R.mipmap.icon_yty,tvAll,0)
                    }else{
                        item.isCheck2=0
                        DrawableUtils.setTextImage(context, R.mipmap.icon_wty,tvAll,0)
                    }
                }else{
                    item.isCheck2=0
                    DrawableUtils.setTextImage(context, R.mipmap.icon_wty,tvAll,0)
                    item.data_list[position].isCheck=0
                    adapter.notifyItemChanged(position)
                }
            }
            tvAll.setOnClickListener {

                if ( item.isCheck2==0){
                    item.isCheck2=1
                    for (b in item.data_list){
                        b.isCheck=1
                    }
                    DrawableUtils.setTextImage(context, R.mipmap.icon_yty,tvAll,0)

                }else{
                    item.isCheck2=0
                    for (b in item.data_list){
                        b.isCheck=0
                    }
                    DrawableUtils.setTextImage(context, R.mipmap.icon_wty,tvAll,0)
                }
                adapter.notifyDataSetChanged()
            }
        }

    }

}